<%--
  Created by IntelliJ IDEA.
  User: 17355
  Date: 2019/6/25
  Time: 16:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" pageEncoding="UTF-8" %>
<%@page import="javax.servlet.http.Cookie" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>用户登录页面</title>
    <style>
        .errCls {
            color: red;
            font-size: 12px;
        }
    </style>
</head>
<body>
<%
    Cookie[] cookies = request.getCookies();
    if (null != cookies) {
        for (int i = 0; i < cookies.length; i++) {
            Cookie cookie = cookies[i];
            if (cookie.getName().equals("userInfo")) {
                String value = cookie.getValue();
                String[] userInfo = value.split("\\|");
                String userName = userInfo[0];
                String password = userInfo[1];
                request.setAttribute("userName", userName);
                request.setAttribute("password", password);
            }
        }
    }
%>
<div>
    <%
        //统计该登录页面的访问次数
        Object count = application.getAttribute("count");
        if (count == null) {
            //第一次访问该页面时，需要创建一个存储访问次数的变量，并将其放进application
            application.setAttribute("count", 1);
        } else {
            //非第一次访问该页面，去application中将记录次数的变量拿出来，+1，将最新访问次数放进application中
            Integer i = (Integer) count;
            application.setAttribute("count", i + 1);
        }
//        Integer iCount = (Integer) application.getAttribute("count");
//        out.print(iCount);

    %>
</div>

<div>
    <form class="log-form" action="${pageContext.request.contextPath}/doLogin02.action" method="post">
        <div>用户名：<input type="text" name="username" value="${userName}"></div>
        <div>密 码：<input type="password" name="password" value="${password}"></div>
        <div class="errCls">${requestScope.errmsg}</div>
        <div>
            <select name="saveTime">
                <option value="having">浏览器进程中</option>
                <option value="oneDay">保存一天</option>
                <option value="oneWeek">保存一周</option>
                <option value="oneMonth">保存一个月</option>
            </select>
        </div>
        <div><input type="submit" value="登录"></div>
    </form>
</div>

</body>
</html>
